from PIL import Image, ImageDraw, ImageFont

c_list = [(0, 0, 0), (0, 0, 170), (0, 170, 0), (0, 170, 170),
(170, 0, 0), (170, 0, 170), (170, 85, 0), (170, 170, 170), 
(85, 85, 85), (85, 85, 255), (85, 255, 85), (85, 255, 255), 
(255, 85, 85), (255, 85, 255), (255, 255, 85), (255, 255, 255)]

i_name = raw_input("Enter your image :\n")

image = Image.open(i_name)

draw = ImageDraw.Draw(image)
no = int(raw_input("Enter the size of your font:\n"))
font = ImageFont.truetype('arial.ttf', size=no)

x1=int(raw_input("Enter x:\n"))
y1 = int(raw_input("Enter y:\n"))
(x,y) = (x1,y1)
message = raw_input("Enter your message(add '/' to split the message):\n")
color = int(raw_input("Last Step! Enter colour number(1-16):\n"))
color = 'rgb'+str(c_list[color-1])
lines = message.split('/')
#print lines

#drawing a message
for line in lines:
    draw.text((x,y), line , fill=color, font= font)
    space = no+3
    y= y+space

#image.show()

parts = i_name.split(".")
name = parts[0]+'2.'+parts[1]
#nameb = parts[0]+'2b.'+parts[1]
image.save(name)

###########################################################
from PIL import ImageOps
 
 
def add_border(input_image, border,color):
    img = Image.open(input_image)
 
    if isinstance(border, int) or isinstance(border, tuple):
        bimg = ImageOps.expand(img, border=border,fill=color)
    else:
        raise RuntimeError('Border is not an integer or tuple!')
 
    bimg.save(name)
    bimg.show()

add_border(name,(30,30,30,30),'rgb(255,255,255)')

